package com.qdlc.p2p.dal.dao.impl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.stereotype.Service;

import com.qdlc.p2p.dal.common.dao.jpa.BaseDaoImpl;
import com.qdlc.p2p.dal.common.model.jpa.OrderFilter.OrderType;
import com.qdlc.p2p.dal.common.model.jpa.PageDataList;
import com.qdlc.p2p.dal.common.model.jpa.QueryParam;
import com.qdlc.p2p.dal.dao.CardSendDao;
import com.qdlc.p2p.dal.dto.CardSend;
import com.qdlc.p2p.dal.model.CardSendModel;

/**
 * Created by lenovo on 2015/12/21.
 */
@Service("cardSendDao")
public class CardSendDaoImpl extends BaseDaoImpl<CardSend> implements CardSendDao{

    @Override
    public PageDataList<CardSendModel> list(CardSendModel model) {
        QueryParam param = QueryParam.getInstance();
        if (model != null) {
            param.addPage(model.getPage(), model.getRows());
        }
        param.addOrder(OrderType.ASC, "id");

        PageDataList<CardSend> pageDateList = super.findPageList(param);
        PageDataList<CardSendModel> pageDateList_ = new PageDataList<CardSendModel>();
        List<CardSendModel> list = new ArrayList<CardSendModel>();
        pageDateList_.setPage(pageDateList.getPage());
        if (pageDateList.getList().size() > 0) {
            for (int i = 0; i < pageDateList.getList().size(); i++) {
                CardSend cs = (CardSend) pageDateList.getList().get(i);
                CardSendModel csm = CardSendModel.instance(cs);
                list.add(csm);
            }
        }
        pageDateList_.setList(list);
        return pageDateList_;
    }
}
